# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cryptography
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.2.2
pkgrel=1
pkgdesc="A package designed to expose cryptographic recipes and primitives to Python developers (mingw-w64)"
url='https://pypi.org/project/cryptography/'
license=('Apache')
arch=('any')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-six"
             "${MINGW_PACKAGE_PREFIX}-python3-six"
             "${MINGW_PACKAGE_PREFIX}-python2-cffi"
             "${MINGW_PACKAGE_PREFIX}-python3-cffi"
             "${MINGW_PACKAGE_PREFIX}-python2-pyasn1"
             "${MINGW_PACKAGE_PREFIX}-python3-pyasn1"
             "${MINGW_PACKAGE_PREFIX}-python2-idna"
             "${MINGW_PACKAGE_PREFIX}-python3-idna"
             "${MINGW_PACKAGE_PREFIX}-python2-asn1crypto"
             "${MINGW_PACKAGE_PREFIX}-python3-asn1crypto"
             "${MINGW_PACKAGE_PREFIX}-python2-enum34"
             "${MINGW_PACKAGE_PREFIX}-python2-ipaddress")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python3-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python2-iso8601"
              "${MINGW_PACKAGE_PREFIX}-python3-iso8601"
              "${MINGW_PACKAGE_PREFIX}-python2-pretend"
              "${MINGW_PACKAGE_PREFIX}-python3-pretend"
              "${MINGW_PACKAGE_PREFIX}-python2-cryptography-vectors"
              "${MINGW_PACKAGE_PREFIX}-python3-cryptography-vectors"
              "${MINGW_PACKAGE_PREFIX}-python2-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python3-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python2-pytz"
              "${MINGW_PACKAGE_PREFIX}-python3-pytz")
source=(https://pypi.io/packages/source/c/cryptography/${_realname}-${pkgver}.tar.gz)
sha256sums=('9fc295bf69130a342e7a19a39d7bbeb15c0bcaabc7382ec33ef3b2b7d18d2f63')

prepare() {
  cd ${srcdir}
  cp -r ${_realname}-${pkgver} python2-build-${CARCH}
  cp -r ${_realname}-${pkgver} python3-build-${CARCH}
}

build() {
  cd "${srcdir}"
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python3-cryptography() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-cffi"
           "${MINGW_PACKAGE_PREFIX}-python3-pyasn1"
           "${MINGW_PACKAGE_PREFIX}-python3-idna"
           "${MINGW_PACKAGE_PREFIX}-python3-asn1crypto")
  cd ${srcdir}/python3-build-${CARCH}
  ${MINGW_PREFIX}/bin/python3 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_python2-cryptography() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-cffi"
           "${MINGW_PACKAGE_PREFIX}-python2-pyasn1"
           "${MINGW_PACKAGE_PREFIX}-python2-idna"
           "${MINGW_PACKAGE_PREFIX}-python2-asn1crypto")
  cd ${srcdir}/python2-build-${CARCH}
  ${MINGW_PREFIX}/bin/python2 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-cryptography() {
  package_python2-cryptography
}

package_mingw-w64-i686-python3-cryptography() {
  package_python3-cryptography
}

package_mingw-w64-x86_64-python2-cryptography() {
  package_python2-cryptography
}

package_mingw-w64-x86_64-python3-cryptography() {
  package_python3-cryptography
}
